Imports cmplib01

Public Class frmAttritionVictoryCondition
    Inherits System.Windows.Forms.Form

    Const c_Module As String = "frmAttritionVictoryCondition"

    Private ptrGameData As CampaignerGameData
    Private ptrAttritVC As AttritionVictoryCondition
    Friend WithEvents btnCancel As System.Windows.Forms.Button

    Private m_Cancelled As Boolean


#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnOK As System.Windows.Forms.Button
    Friend WithEvents pnlObjectiveProperties As System.Windows.Forms.Panel
    Friend WithEvents lblDescription As System.Windows.Forms.Label
    Friend WithEvents lblAutomaticVictory As System.Windows.Forms.Label
    Friend WithEvents lblVictoryPointValue As System.Windows.Forms.Label
    Friend WithEvents lblVictoryConditionName As System.Windows.Forms.Label
    Friend WithEvents txtDescription As System.Windows.Forms.TextBox
    Friend WithEvents chkAutomaticVictory As System.Windows.Forms.CheckBox
    Friend WithEvents numVPValue As System.Windows.Forms.NumericUpDown
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents chkTotalDeployedReduction As System.Windows.Forms.CheckBox
    Friend WithEvents chkTotalPointValueReduction As System.Windows.Forms.CheckBox
    Friend WithEvents lblPercent As System.Windows.Forms.Label
    Friend WithEvents lblMorePercent As System.Windows.Forms.Label
    Friend WithEvents numDeployed As System.Windows.Forms.NumericUpDown
    Friend WithEvents numTotal As System.Windows.Forms.NumericUpDown
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Dim resources As System.ComponentModel.ComponentResourceManager = New System.ComponentModel.ComponentResourceManager(GetType(frmAttritionVictoryCondition))
        Me.btnOK = New System.Windows.Forms.Button
        Me.pnlObjectiveProperties = New System.Windows.Forms.Panel
        Me.lblMorePercent = New System.Windows.Forms.Label
        Me.lblPercent = New System.Windows.Forms.Label
        Me.numTotal = New System.Windows.Forms.NumericUpDown
        Me.numDeployed = New System.Windows.Forms.NumericUpDown
        Me.chkTotalPointValueReduction = New System.Windows.Forms.CheckBox
        Me.chkTotalDeployedReduction = New System.Windows.Forms.CheckBox
        Me.lblDescription = New System.Windows.Forms.Label
        Me.lblAutomaticVictory = New System.Windows.Forms.Label
        Me.lblVictoryPointValue = New System.Windows.Forms.Label
        Me.lblVictoryConditionName = New System.Windows.Forms.Label
        Me.txtDescription = New System.Windows.Forms.TextBox
        Me.chkAutomaticVictory = New System.Windows.Forms.CheckBox
        Me.numVPValue = New System.Windows.Forms.NumericUpDown
        Me.txtName = New System.Windows.Forms.TextBox
        Me.btnCancel = New System.Windows.Forms.Button
        Me.pnlObjectiveProperties.SuspendLayout()
        CType(Me.numTotal, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.numDeployed, System.ComponentModel.ISupportInitialize).BeginInit()
        CType(Me.numVPValue, System.ComponentModel.ISupportInitialize).BeginInit()
        Me.SuspendLayout()
        '
        'btnOK
        '
        Me.btnOK.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnOK.Location = New System.Drawing.Point(156, 286)
        Me.btnOK.Name = "btnOK"
        Me.btnOK.Size = New System.Drawing.Size(75, 23)
        Me.btnOK.TabIndex = 3
        Me.btnOK.Text = "OK"
        '
        'pnlObjectiveProperties
        '
        Me.pnlObjectiveProperties.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.pnlObjectiveProperties.Controls.Add(Me.lblMorePercent)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblPercent)
        Me.pnlObjectiveProperties.Controls.Add(Me.numTotal)
        Me.pnlObjectiveProperties.Controls.Add(Me.numDeployed)
        Me.pnlObjectiveProperties.Controls.Add(Me.chkTotalPointValueReduction)
        Me.pnlObjectiveProperties.Controls.Add(Me.chkTotalDeployedReduction)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblDescription)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblAutomaticVictory)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblVictoryPointValue)
        Me.pnlObjectiveProperties.Controls.Add(Me.lblVictoryConditionName)
        Me.pnlObjectiveProperties.Controls.Add(Me.txtDescription)
        Me.pnlObjectiveProperties.Controls.Add(Me.chkAutomaticVictory)
        Me.pnlObjectiveProperties.Controls.Add(Me.numVPValue)
        Me.pnlObjectiveProperties.Controls.Add(Me.txtName)
        Me.pnlObjectiveProperties.Location = New System.Drawing.Point(8, 8)
        Me.pnlObjectiveProperties.Name = "pnlObjectiveProperties"
        Me.pnlObjectiveProperties.Size = New System.Drawing.Size(304, 272)
        Me.pnlObjectiveProperties.TabIndex = 2
        '
        'lblMorePercent
        '
        Me.lblMorePercent.Location = New System.Drawing.Point(272, 96)
        Me.lblMorePercent.Name = "lblMorePercent"
        Me.lblMorePercent.Size = New System.Drawing.Size(16, 16)
        Me.lblMorePercent.TabIndex = 15
        Me.lblMorePercent.Text = "%"
        '
        'lblPercent
        '
        Me.lblPercent.Location = New System.Drawing.Point(272, 64)
        Me.lblPercent.Name = "lblPercent"
        Me.lblPercent.Size = New System.Drawing.Size(16, 16)
        Me.lblPercent.TabIndex = 14
        Me.lblPercent.Text = "%"
        '
        'numTotal
        '
        Me.numTotal.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numTotal.Enabled = False
        Me.numTotal.Location = New System.Drawing.Point(216, 94)
        Me.numTotal.Name = "numTotal"
        Me.numTotal.Size = New System.Drawing.Size(48, 20)
        Me.numTotal.TabIndex = 13
        Me.numTotal.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numTotal.Value = New Decimal(New Integer() {40, 0, 0, 0})
        '
        'numDeployed
        '
        Me.numDeployed.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numDeployed.Enabled = False
        Me.numDeployed.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numDeployed.Location = New System.Drawing.Point(216, 62)
        Me.numDeployed.Name = "numDeployed"
        Me.numDeployed.Size = New System.Drawing.Size(48, 20)
        Me.numDeployed.TabIndex = 12
        Me.numDeployed.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numDeployed.Value = New Decimal(New Integer() {50, 0, 0, 0})
        '
        'chkTotalPointValueReduction
        '
        Me.chkTotalPointValueReduction.Location = New System.Drawing.Point(8, 96)
        Me.chkTotalPointValueReduction.Name = "chkTotalPointValueReduction"
        Me.chkTotalPointValueReduction.Size = New System.Drawing.Size(208, 16)
        Me.chkTotalPointValueReduction.TabIndex = 11
        Me.chkTotalPointValueReduction.Text = "Reduce Enemy Total Point Value To"
        '
        'chkTotalDeployedReduction
        '
        Me.chkTotalDeployedReduction.Location = New System.Drawing.Point(8, 64)
        Me.chkTotalDeployedReduction.Name = "chkTotalDeployedReduction"
        Me.chkTotalDeployedReduction.Size = New System.Drawing.Size(208, 16)
        Me.chkTotalDeployedReduction.TabIndex = 10
        Me.chkTotalDeployedReduction.Text = "Reduce Enemy Deployed Points To"
        '
        'lblDescription
        '
        Me.lblDescription.Location = New System.Drawing.Point(8, 176)
        Me.lblDescription.Name = "lblDescription"
        Me.lblDescription.Size = New System.Drawing.Size(184, 16)
        Me.lblDescription.TabIndex = 9
        Me.lblDescription.Text = "Victory Condition Description"
        '
        'lblAutomaticVictory
        '
        Me.lblAutomaticVictory.Location = New System.Drawing.Point(160, 120)
        Me.lblAutomaticVictory.Name = "lblAutomaticVictory"
        Me.lblAutomaticVictory.Size = New System.Drawing.Size(128, 16)
        Me.lblAutomaticVictory.TabIndex = 8
        Me.lblAutomaticVictory.Text = "Automatic Victory"
        '
        'lblVictoryPointValue
        '
        Me.lblVictoryPointValue.Location = New System.Drawing.Point(8, 120)
        Me.lblVictoryPointValue.Name = "lblVictoryPointValue"
        Me.lblVictoryPointValue.Size = New System.Drawing.Size(128, 16)
        Me.lblVictoryPointValue.TabIndex = 7
        Me.lblVictoryPointValue.Text = "Victory Point Value"
        '
        'lblVictoryConditionName
        '
        Me.lblVictoryConditionName.Location = New System.Drawing.Point(8, 8)
        Me.lblVictoryConditionName.Name = "lblVictoryConditionName"
        Me.lblVictoryConditionName.Size = New System.Drawing.Size(128, 16)
        Me.lblVictoryConditionName.TabIndex = 5
        Me.lblVictoryConditionName.Text = "Victory Condition Name"
        '
        'txtDescription
        '
        Me.txtDescription.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtDescription.Location = New System.Drawing.Point(11, 200)
        Me.txtDescription.Multiline = True
        Me.txtDescription.Name = "txtDescription"
        Me.txtDescription.Size = New System.Drawing.Size(280, 56)
        Me.txtDescription.TabIndex = 4
        Me.txtDescription.Text = "No Victory Condition Description"
        '
        'chkAutomaticVictory
        '
        Me.chkAutomaticVictory.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.chkAutomaticVictory.Location = New System.Drawing.Point(160, 144)
        Me.chkAutomaticVictory.Name = "chkAutomaticVictory"
        Me.chkAutomaticVictory.Size = New System.Drawing.Size(120, 24)
        Me.chkAutomaticVictory.TabIndex = 3
        Me.chkAutomaticVictory.Text = "Automatic Victory"
        '
        'numVPValue
        '
        Me.numVPValue.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.numVPValue.Increment = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numVPValue.Location = New System.Drawing.Point(8, 144)
        Me.numVPValue.Minimum = New Decimal(New Integer() {5, 0, 0, 0})
        Me.numVPValue.Name = "numVPValue"
        Me.numVPValue.Size = New System.Drawing.Size(120, 20)
        Me.numVPValue.TabIndex = 2
        Me.numVPValue.TextAlign = System.Windows.Forms.HorizontalAlignment.Center
        Me.numVPValue.Value = New Decimal(New Integer() {5, 0, 0, 0})
        '
        'txtName
        '
        Me.txtName.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle
        Me.txtName.Location = New System.Drawing.Point(8, 32)
        Me.txtName.Name = "txtName"
        Me.txtName.Size = New System.Drawing.Size(280, 20)
        Me.txtName.TabIndex = 0
        Me.txtName.Text = "No Victory Condition Name"
        '
        'btnCancel
        '
        Me.btnCancel.FlatStyle = System.Windows.Forms.FlatStyle.Flat
        Me.btnCancel.Location = New System.Drawing.Point(237, 286)
        Me.btnCancel.Name = "btnCancel"
        Me.btnCancel.Size = New System.Drawing.Size(75, 23)
        Me.btnCancel.TabIndex = 4
        Me.btnCancel.Text = "Cancel"
        '
        'frmAttritionVictoryCondition
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(320, 318)
        Me.Controls.Add(Me.btnCancel)
        Me.Controls.Add(Me.btnOK)
        Me.Controls.Add(Me.pnlObjectiveProperties)
        Me.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle
        Me.Icon = CType(resources.GetObject("$this.Icon"), System.Drawing.Icon)
        Me.Name = "frmAttritionVictoryCondition"
        Me.Text = "Victory Condition"
        Me.pnlObjectiveProperties.ResumeLayout(False)
        Me.pnlObjectiveProperties.PerformLayout()
        CType(Me.numTotal, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.numDeployed, System.ComponentModel.ISupportInitialize).EndInit()
        CType(Me.numVPValue, System.ComponentModel.ISupportInitialize).EndInit()
        Me.ResumeLayout(False)

    End Sub

#End Region

    Public ReadOnly Property Cancelled() As Boolean
        Get
            Return m_Cancelled
        End Get
    End Property

    Public Sub New(ByRef AVC As AttritionVictoryCondition, ByVal GameData As CampaignerGameData)
        Me.New()

        Try
            ptrGameData = GameData
            ptrAttritVC = AVC

            ListProperties()
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try
    End Sub

    Private Sub ListProperties()
        Try
            txtName.Text = ptrAttritVC.VictoryConditionName
            txtDescription.Text = ptrAttritVC.Description
            numVPValue.Value = ptrAttritVC.VPValue
            chkAutomaticVictory.Checked = ptrAttritVC.AutomaticVictory

            ' list properties for attrition values
            If ptrAttritVC.DeployedReductionPercent <> -1 Then
                Me.chkTotalDeployedReduction.Checked = True
                numDeployed.Value = ptrAttritVC.DeployedReductionPercent
            End If

            If ptrAttritVC.TotalPointValueReductionPercent <> -1 Then
                Me.chkTotalPointValueReduction.Checked = True
                numTotal.Value = ptrAttritVC.TotalPointValueReductionPercent
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

    End Sub

    Private Function SaveProperties() As Boolean
        Try
            ptrAttritVC.VictoryConditionName = txtName.Text
            ptrAttritVC.Description = txtDescription.Text
            ptrAttritVC.AutomaticVictory = chkAutomaticVictory.Checked
            ptrAttritVC.VPValue = numVPValue.Value
            If chkTotalDeployedReduction.Checked = True Then
                ptrAttritVC.DeployedReductionPercent = numDeployed.Value
            Else
                ptrAttritVC.DeployedReductionPercent = -1
            End If
            If chkTotalPointValueReduction.Checked = True Then
                ptrAttritVC.TotalPointValueReductionPercent = numTotal.Value
            Else
                ptrAttritVC.TotalPointValueReductionPercent = -1
            End If
        Catch ex As Exception
            HandleException(c_Module, ex)
        End Try

        Return True

    End Function

    Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
        If SaveProperties() = True Then
            Me.Hide()
        End If
    End Sub

    Private Sub chkTotalDeployedReduction_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTotalDeployedReduction.CheckedChanged
        If chkTotalDeployedReduction.Checked = True Then
            numDeployed.Enabled = True
        Else
            numDeployed.Enabled = False
        End If
    End Sub

    Private Sub chkTotalPointValueReduction_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles chkTotalPointValueReduction.CheckedChanged
        If chkTotalPointValueReduction.Checked = True Then
            numTotal.Enabled = True
        Else
            numTotal.Enabled = False
        End If
    End Sub

    Private Sub btnCancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCancel.Click
        m_Cancelled = True
        Me.Hide()
    End Sub
End Class
